//
// Created by Gorun on 2022/5/2.
//

#ifndef LOXPP_SCANNER_H
#define LOXPP_SCANNER_H
#include "Token/Token.h"
#include <cctype>
#include <vector>
#include <string>
#include <map>

class Scanner {
public:
    explicit Scanner(const std::string& source);
    void setSource(const std::string& s);
    std::string getSource() const;
    std::vector<Token> scanTokens();

private:
    void scanToken();
    void identifier();
    void number();
    void string();
    bool match(char expected);
    char peek();
    char peekNext();
    static bool isAlpha(char ch);
    static bool isDigit(char ch);
    static bool isAlphaNumberic(char ch);
    bool isAtEnd();
    char advance();
    void addToken(TokenType type);
    void addToken(TokenType type, const Object* literal);

    std::string source;
    std::vector<Token> tokens;
    std::map<std::string, TokenType> keywords;
    int start=0;
    int current=0;
    int line=1;
    int column=1;
};


#endif //LOXPP_SCANNER_H
